package com.service.impl;

import com.bean.Menu;
import com.dao.MenuDao;
import com.dao.impl.MenuDaoImpl;
import com.service.MenuService;

import java.util.ArrayList;
import java.util.List;

public class MenuServiceImpl implements MenuService {
    private MenuDao menuDao = new MenuDaoImpl();

    @Override
    public List<Menu> getMenuList() {
        List<Menu> menuList = menuDao.getMenuList();
        List<Menu> newMenuList = new ArrayList<>();
        for (Menu menu: menuList) {
            if(menu.getUpMenuId()==0){//说明是一级菜单
                List<Menu> secondList = new ArrayList<>();
                for (Menu second: menuList) {
                    if(second.getUpMenuId()==menu.getMenuId()){//说明是二级菜单
                        secondList.add(second);
                    }
                }
               menu.setSecondMenuList(secondList);
                newMenuList.add(menu);
            }
        }
        return newMenuList;
    }

    @Override
    public List<Menu> getMenusList(int pageIndex,int pageSize) {
        return menuDao.getMenusList(pageIndex,pageSize);
    }

    @Override
    public int total() {
        return menuDao.total();
    }
}
